<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="computeTaskFormQueryRef" :model="computeTaskFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!computeTaskFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="computeTaskFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="computeTaskFormQuerySubmitting" @search="computeTaskFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="computeTaskFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="computeTaskFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="computeTaskFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="computeTaskFormQuerySubmitting" @search="computeTaskFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="任务名称">
              <a-input v-model:value="computeTaskFormQueryModel.taskNameAndLike" placeholder="输入任务名称" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="分类">
              <a-input v-model:value="computeTaskFormQueryModel.taskTypeAndLike" placeholder="输入分类" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="描述">
              <a-input v-model:value="computeTaskFormQueryModel.descriptionAndLike" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="computeTaskFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="computeTaskFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="computeTaskFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="computeTaskFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="computeTaskFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="computeTaskAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="computeTaskListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="computeTaskUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="computeTaskListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="computeTaskDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="computeTaskListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="computeTaskDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
        <a-button v-if="computeTaskListSelectLength === 1" type="dashed" :style="{ 'color': '#9254de' }" @click="computeTaskCompute">
          <CoreIcon icon="whh:lightning" color="#ed6f6f" :size="14" />
          计算
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="computeTaskTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="computeTaskDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="computeTaskDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="computeTaskListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="computeTaskListColumns"
        :data-source="computeTaskListDataSet"
        :loading="computeTaskListLoading"
        :pagination="false"
        bordered
        :customRow="computeTaskListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: computeTaskListSelectedRowKeys, onChange: computeTaskListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="computeTaskListDataPage"
        v-model:pageSize="computeTaskListDataRows"
        :total="computeTaskListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="computeTaskListPaginationChange"
        @showSizeChange="computeTaskListPaginationShowSizeChange"
        v-if="computeTaskListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!computeTaskListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(computeTaskListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="computeTaskEditDrawerVisible"
      title="编辑计算任务信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="computeTaskEditDrawerOnClose"
    >
      <a-form ref="computeTaskFormRef" :model="computeTaskFormModel" :rules="computeTaskFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="任务名称" name="taskName">
              <a-input v-model:value="computeTaskFormModel.taskName" placeholder="输入任务名称" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="分类" name="taskType">
              <a-input v-model:value="computeTaskFormModel.taskType" placeholder="输入分类" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="描述" name="description">
              <a-input v-model:value="computeTaskFormModel.description" placeholder="输入描述" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="computeTaskFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="computeTaskFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="computeTaskFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="computeTaskFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="computeTaskFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="computeTaskFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="computeTaskDetailDrawerVisible"
      title="计算任务详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="任务名称" :span="1">{{ computeTaskDetailModel.taskName }}</a-descriptions-item>
          <a-descriptions-item label="分类" :span="1">{{ computeTaskDetailModel.taskType }}</a-descriptions-item>
          <a-descriptions-item label="描述" :span="1">{{ computeTaskDetailModel.description }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ computeTaskDetailModel.weightOrder }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="computeTaskDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="computeTaskDataImportDrawerVisible"
      title="计算任务数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="computeTaskDataImportFileUploadRef" :fileModule="computeTaskDataImportFileModule" @change="computeTaskDataImportFileUploadChange" />
          <a-input v-model:value="computeTaskDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="computeTaskDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="computeTaskDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="computeTaskToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="computeTaskDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="computeTaskDataImportFileModule" @change="computeTaskDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="computeTaskDataExportDrawerVisible"
      title="计算任务数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="computeTaskOptionalDataExportFieldList" :selectedDataExportFieldList="computeTaskSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="computeTaskToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="computeTaskToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useComputeTaskStore } from '/@/store/modules/cn/core/kpis/computeTaskStore'

import type { ComputeTask } from '/@/model/cn/core/kpis/eo/ComputeTask'
import { toComputeTask } from '/@/model/cn/core/kpis/eo/ComputeTask'

import type { ComputeTaskQO } from '/@/model/cn/core/kpis/qo/ComputeTaskQO'
import { toComputeTaskQO } from '/@/model/cn/core/kpis/qo/ComputeTaskQO'

import type { ComputeTaskVO } from '/@/model/cn/core/kpis/vo/ComputeTaskVO'
import { toComputeTaskVO } from '/@/model/cn/core/kpis/vo/ComputeTaskVO'

@Options({
  name: 'ComputeTask',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useComputeTaskStore),
  },
})
export default class ComputeTask extends Vue {

  computeTaskListDataSet: Array<ComputeTaskVO> = []

  computeTaskListColumns: Array<object> = [
    {
      title: '任务名称',
      dataIndex: 'taskName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '分类',
      dataIndex: 'taskType',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '描述',
      dataIndex: 'description',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  computeTaskListLoading: boolean = false

  computeTaskListSelectedRowKeys: string[] = []

  computeTaskListSelectData: Array<ComputeTaskVO> = []

  computeTaskListSelectLength: number = 0

  computeTaskListSelectCurrentRowIndex: number = -1

  computeTaskListSelectCurrentRowData: ComputeTaskVO = toComputeTaskVO()

  computeTaskListPaginationVisible: boolean = true

  computeTaskListDataPage: number = 1

  computeTaskListDataRows: number = 10

  computeTaskListDataCount: number = 0

  computeTaskListRowClickTimeout: number | null = null

  computeTaskListRowOnChange(selectedRowKeys, selectedRows) {
    this.computeTaskListSelectedRowKeys = [ ...selectedRowKeys ]
    this.computeTaskListSelectData = [ ...selectedRows ]
    this.computeTaskListSelectLength = selectedRows.length
  }

  computeTaskListCustomRow(record, index) {
    return {
      'class': index === this.computeTaskListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.computeTaskListRowClickTimeout) {
          clearTimeout(this.computeTaskListRowClickTimeout)
          this.computeTaskListRowClickTimeout = null
        } else {
          this.computeTaskListRowClickTimeout = setTimeout(() => {
            this.computeTaskListRowClickTimeout = null
            this.computeTaskListSelectCurrentRowIndex = index
            this.computeTaskListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.computeTaskListSelectedRowKeys ]
            let selectedRows = [ ...this.computeTaskListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.computeTaskListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.computeTaskListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.computeTaskStore.pkVo(this.$toParam<ComputeTaskQO>({ id: record.id } as ComputeTaskQO)).then((res: Res<ComputeTaskVO>) => {
          if (res.succ) {
            this.computeTaskDetailModel = { ...res.data[0] }
            this.computeTaskDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  computeTaskListGetDataSet() {
    this.computeTaskListLoading = true
    this.computeTaskListRowOnChange([], [])
    this.computeTaskListSelectCurrentRowIndex = -1
    this.computeTaskListSelectCurrentRowData = toComputeTaskVO()
    this.computeTaskStore.pagingVo(this.$toParam<ComputeTaskQO>({ weightOrderAsc: 'y' } as ComputeTaskQO, this.computeTaskListDataPage, this.computeTaskListDataRows)).then((res: Res<ComputeTaskVO>) => {
      if (res.succ) {
        this.computeTaskListPaginationVisible = true
        this.computeTaskListDataSet = [ ...res.data ]
        this.computeTaskListDataCount = res.count
        setTimeout(() => { this.computeTaskListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.computeTaskListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.computeTaskListLoading = false }, 500)
    })
  }

  computeTaskListPaginationChange() {
    this.computeTaskListGetDataSet()
  }

  computeTaskListPaginationShowSizeChange() {
    this.computeTaskListGetDataSet()
  }

  computeTaskFormQueryVisible: boolean = false

  computeTaskFormQuerySubmitting: boolean = false

  computeTaskFormQueryModel: ComputeTaskQO = toComputeTaskQO()

  computeTaskFormQueryUpDown() {
    this.computeTaskFormQueryVisible = !this.computeTaskFormQueryVisible
  }

  computeTaskFormQueryReset() {
    if (this.$refs.computeTaskFormQueryRef) {
      this.$refs.computeTaskFormQueryRef.resetFields()
      this.computeTaskFormQueryModel = toComputeTaskQO()
    }
  }

  computeTaskFormQuerySearch() {
    this.computeTaskFormQuerySubmitting = true
    this.computeTaskListLoading = true
    this.computeTaskListRowOnChange([], [])
    this.computeTaskListSelectCurrentRowIndex = -1
    this.computeTaskListSelectCurrentRowData = toComputeTaskVO()
    this.computeTaskStore.queryVo(this.$toParam<ComputeTaskQO>(this.$toSearch({ ...this.computeTaskFormQueryModel }))).then((res: Res<ComputeTaskVO>) => {
      if (res.succ) {
        this.computeTaskListPaginationVisible = false
        this.computeTaskListDataSet = [ ...res.data ]
        this.computeTaskListDataCount = res.count
        setTimeout(() => { this.computeTaskFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.computeTaskListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.computeTaskFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.computeTaskListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.computeTaskFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.computeTaskListLoading = false }, 500)
    })
  }

  computeTaskEditDrawerVisible: boolean = false

  computeTaskFormSaveSubmitting: boolean = false

  computeTaskFormSaveContinue: boolean = false

  computeTaskFormModel: ComputeTask = toComputeTask()

  computeTaskFormRules: object = {
    // taskName: [
    //   { type: 'string', required: true, message: '任务名称不能为空！', trigger: ['change', 'blur'] },
    // ],
    // taskType: [
    //   { type: 'string', required: true, message: '分类不能为空！', trigger: ['change', 'blur'] },
    // ],
    // description: [
    //   { type: 'string', required: true, message: '描述不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  computeTaskFormReset() {
    if (this.$refs.computeTaskFormRef) {
      this.$refs.computeTaskFormRef.resetFields()
      this.computeTaskFormModel = toComputeTask()
    }
  }

  computeTaskFormSubmit() {
    this.computeTaskFormSaveSubmitting = true
    this.$refs.computeTaskFormRef.validate().then(() => {
      if (this.computeTaskFormModel.id) {
        this.computeTaskStore.update(this.$toParam<ComputeTask>(this.computeTaskFormModel)).then((res: Res<ComputeTask>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.computeTaskFormReset()
            this.computeTaskFormSaveSubmitting = false
            if (!this.computeTaskFormSaveContinue) {
              this.computeTaskEditDrawerVisible = false
              this.computeTaskListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.computeTaskFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.computeTaskFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.computeTaskStore.save(this.$toParam<ComputeTask>(this.computeTaskFormModel)).then((res: Res<ComputeTask>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.computeTaskFormReset()
            this.computeTaskFormSaveSubmitting = false
            if (!this.computeTaskFormSaveContinue) {
              this.computeTaskEditDrawerVisible = false
              this.computeTaskListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.computeTaskFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.computeTaskFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.computeTaskFormSaveSubmitting = false }, 3000)
    })
  }

  computeTaskFormSave() {
    this.computeTaskFormSaveContinue = false
    this.computeTaskFormSubmit()
  }

  computeTaskFormNextAdd() {
    this.computeTaskFormSaveContinue = true
    this.computeTaskFormSubmit()
  }

  computeTaskAdd() {
    if (this.computeTaskFormModel.id) {
      this.computeTaskFormReset()
    }
    this.computeTaskEditDrawerVisible = true
  }

  computeTaskUpdate() {
    this.computeTaskStore.pk(this.$toParam<ComputeTaskQO>({ id: this.computeTaskListSelectData[0].id } as ComputeTaskQO)).then((res: Res<ComputeTask>) => {
      if (res.succ) {
        this.computeTaskFormReset()
        this.computeTaskFormModel = { ...res.data[0] }
        this.computeTaskEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  computeTaskEditDrawerOnClose() {
    if (this.computeTaskFormSaveContinue) {
      this.computeTaskFormSaveContinue = false
      this.computeTaskListGetDataSet()
    }
  }

  computeTaskDelete() {
    let param: Array<ComputeTask> = []
    this.computeTaskListSelectData.forEach((eo: ComputeTaskVO) => {
      param.push({ id: eo.id } as ComputeTask)
    })
    this.computeTaskStore.removeBatch(this.$toParam<ComputeTask>(param)).then((res: Res<ComputeTask>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.computeTaskListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  computeTaskDetailDrawerVisible: boolean = false

  computeTaskDetailModel: ComputeTaskVO = toComputeTaskVO()

  computeTaskDetailInfo() {
    this.computeTaskStore.pkVo(this.$toParam<ComputeTaskQO>({ id: this.computeTaskListSelectData[0].id } as ComputeTaskQO)).then((res: Res<ComputeTaskVO>) => {
      if (res.succ) {
        this.computeTaskDetailModel = { ...res.data[0] }
        this.computeTaskDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  computeTaskDetailUpdate() {
    this.computeTaskStore.pk(this.$toParam<ComputeTaskQO>({ id: this.computeTaskDetailModel.id } as ComputeTaskQO)).then((res: Res<ComputeTask>) => {
      if (res.succ) {
        this.computeTaskFormReset()
        this.computeTaskFormModel = { ...res.data[0] }
        this.computeTaskDetailDrawerVisible = false
        this.computeTaskEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  computeTaskCompute() {
    this.computeTaskStore.compute(this.$toParam<ComputeTask>({ id: this.computeTaskListSelectData[0].id } as ComputeTask)).then((res: Res<ComputeTask>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  computeTaskTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  computeTaskDataImportDrawerVisible: boolean = false

  computeTaskDataImportFileSelectDrawerVisible: boolean = false

  computeTaskDataImportFileModule: string = 'dataImport'

  computeTaskDataImportFileUrl: string = ''

  computeTaskDataImportSaveSubmitting: boolean = false

  computeTaskDataImport() {
    this.computeTaskDataImportDrawerVisible = true
  }

  computeTaskDataImportFileUploadChange(value) {
    this.computeTaskDataImportFileUrl = value
  }

  computeTaskDataImportFileUrlSelectFileClick() {
    this.computeTaskDataImportFileSelectDrawerVisible = true
  }

  computeTaskDataImportFileSelectChange(fileUrl) {
    this.computeTaskDataImportFileUrl = fileUrl
    this.computeTaskDataImportFileSelectDrawerVisible = false
  }

  computeTaskToDataImport() {
    this.computeTaskDataImportSaveSubmitting = true
    this.computeTaskStore.dataImport(this.$toParam<string>(this.computeTaskDataImportFileUrl)).then((res: Res<ComputeTask>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.computeTaskDataImportFileUploadRef.resetFiles()
        this.computeTaskDataImportFileUrl = ''
        this.computeTaskDataImportSaveSubmitting = false
        this.computeTaskDataImportDrawerVisible = false
        this.computeTaskListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.computeTaskDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.computeTaskDataImportSaveSubmitting = false }, 3000)
    })
  }

  computeTaskDataExportDrawerVisible: boolean = false

  computeTaskOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'taskName',
      fieldComment: '任务名称',
    },
    {
      fieldName: 'taskType',
      fieldComment: '分类',
    },
    {
      fieldName: 'description',
      fieldComment: '描述',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
  ]

  computeTaskSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  computeTaskDataExport() {
    this.computeTaskDataExportDrawerVisible = true
  }

  computeTaskToDataExport(allData: boolean) {
    this.computeTaskStore.dataExport(this.$toParam<DataExportAO<ComputeTaskQO>>(toDataExportAO(this.computeTaskSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as ComputeTaskQO : this.$toSearch({ ...this.computeTaskFormQueryModel }), '计算任务信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    this.computeTaskListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
